<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/jsp/common/common.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>	
	<script language="javascript" src="<%=contextPath%>/js/func.js"type=""></script>
	<script type="text/javascript" src="<%=contextPath%>/js/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript">
	Ext.onReady(function(){
		var tb = new Ext.Toolbar({
		    renderTo: Ext.get('tbar'),
		    items: [
		        {
		            text: '查询',
		             icon:"<%=contextPath%>/" + "images/query.gif",
		             hidden:<%=session.getAttribute("btn_query_display") != null || "1".equals(session.getAttribute("SESSION_ISADMIN")) ? false:true%>,
		             handler:cmt
		        }, {
		            text: '起草',
		            icon:"<%=contextPath%>/" + "images/tishi.png",
		            hidden:<%=session.getAttribute("btn_add_display") != null || "1".equals(session.getAttribute("SESSION_ISADMIN")) ? false:true%>,
		            handler:function() {
		            	toDetail('0')
		            }
		        }, 
		        {
		            text: '删除',
		            icon:"<%=contextPath%>/" + "images/delete.gif",
		            hidden:<%=session.getAttribute("btn_delete_display") != null || "1".equals(session.getAttribute("SESSION_ISADMIN")) ? false:true%>,
		            handler:deleteIt
		        },'-',
				{
				     text: '清空',
				     icon:"<%=contextPath%>/images/clear.png",
				     handler:resetForm
				}]
		});
	});
	</script>
  </head>
  <body>
 <body>
  <div id ='tbar'></div>
  <br>
		<div id="Layer" style="position:absolute;display:block left:0px; top:35px; width:100%; height:94%; z-index:1000; overflow:auto;">
		<form id="frmM" class="ct" name="frmM" method="POST" action="<%=contextPath%>/queryUser.do">
			<input type="hidden" id="hiddenids" name="hiddenids" value="${hiddenids}"/>
			<input type="hidden" name="searchBean.displayFlag" value="${searchBean.displayFlag}"/>
			<input type="hidden" name="searchBean.con1" id="searchBean.con1" value="${searchBean.con1}" >
			<input type="hidden" name="searchBean.con6" id="searchBean.con6" value="${searchBean.con6}" >
			<input type="hidden" name="conditionHtml" />
			<table width="100%" id="contab" >
				<c:if test="${searchBean.con20 == '0' || searchBean.con20 == '1'}">
				<tr>
					<th >工作开始时间：</th >
					<td  align="left">
					<input type="text"  size="12" readonly="true" onclick="WdatePicker({el:$dp.$('searchBean.con2')})" name="searchBean.con2" id="searchBean.con2" value=${searchBean.con2 }>
					<img onclick="WdatePicker({dateFmt:'yyyy-MM-dd',el:$dp.$('searchBean.con2')})" src="<%=contextPath%>/js/My97DatePicker/skin/datePicker.gif" width="16" height="22" align="absmiddle">
					
					~
					<input type="text" size="12" readonly="true" onclick="WdatePicker({el:$dp.$('searchBean.con3')})"  name="searchBean.con3" id="searchBean.con3" value=${searchBean.con3 }>
					<img onclick="WdatePicker({dateFmt:'yyyy-MM-dd',el:$dp.$('searchBean.con3')})" src="<%=contextPath%>/js/My97DatePicker/skin/datePicker.gif" width="16" height="22" align="absmiddle">
					</td>
					<th >变电站</th >
					<td  align="left">
						<input type="hidden" name="searchBean.con4" id="searchBean.con4" value="${searchBean.con4}" >
						<input type="text" readonly="true" name="searchBean.con5" size="50" id="searchBean.con5" value="${searchBean.con5}"/>
						<img style='cursor:pointer' src="<%=contextPath%>/images/editlink.gif" title="选择变电站" 
							onClick="javascript:getBdzselect('searchBean.con4','searchBean.con5','searchBean.con1')" />
					</td>
				</tr>
				</c:if>
			</table>
		<hr>
		<table width="100%" id="listtab">
    		<tr>
    			<th width="25">
				<input name="chkAll" type="checkbox" id="chkAll" onclick="javascript:checkAll(this.form, 'id');" value="checkbox">
				</th>
				<th class="ct" width="10">
					折叠
				</th>
				<th class="ct" width="10">序号</th>
				<th class="ct" >变电站</th>
				<th class="ct" >工作负责人</th>
 			    <th class="ct" width="250">工作内容</th>
				<th class="ct">开始时间</th>
				<th class="ct" >结束时间</th>
				<th class="ct" >领用人</th>
				<th class="ct" >领用日期</th>
				
			</tr>
			<c:forEach items="${list}" var="Tab" varStatus="status">
					<tr ondblclick="javascript:toDetail('<c:out value="${Tab.id}"/>')"s>
						<td >
								<c:set value="${Tab.id}," var="varName" />
								<c:if test='${fn:contains(hiddenids, varName)}'>
									<input type="checkbox" name="id" value="${Tab.id}" checked onClick="getAllIds(this)"/>
								</c:if>
								<c:if test='${fn:contains(hiddenids, varName) == false}'>
									<input type="checkbox" name="id" value="${Tab.id}" onClick="getAllIds(this)"/>
								</c:if>
						</td>
						<td width="5">
					 		<img id="imgo${Tab.id}" onclick="openDetail('${Tab.id}')" src="<%=contextPath%>/images/plus1.gif" align="absmiddle">
					 		<img id="imgc${Tab.id}" style="display:none" onclick="openDetail('${Tab.id}')" src="<%=contextPath%>/images/minus1.gif" align="absmiddle">
						</td>
						<td width="5"> 
						<a href="#" onClick="javascript:toDetail('<c:out value="${Tab.id}"/>')" >${status.index+1}
						</a>
					 		</td>
					 		<td>${Tab['stationname']}</td>
					 		<td>${Tab['fzrname']}</td>
				
						<td width="250" style="text-align: left">${Tab['workcontent']}</td>
		
						<td width="120">
						
						<fmt:formatDate value="${Tab.startdate}" pattern="yyyy-MM-dd HH:mm"/>	
						</td>
						<td width="120">
							<fmt:formatDate value="${Tab.enddate}" pattern="yyyy-MM-dd HH:mm"/>	
							</td>
						
						<td>${Tab['lyrname']}</td>
						<td>
						<fmt:formatDate value="${Tab.lydate}" pattern="yyyy-MM-dd"/>	
						</td>
						
					</tr>
					<tr height="0" id="tr${Tab.id}" style="display:none"><td></td><td colspan="14"><div id="nr${Tab.id}"></div></td></tr>
					<tr height="0" style="display:none"><td></td><td colspan="14"></td></tr>
				</c:forEach>

				<c:if test="${list == null || fn:length(list) == 0 }">
					<tr>
						<td colspan="12" style="text-align: center">
							无相关记录
						</td>
					</tr>
				</c:if>
		</table>
			<table width="100%" id="tablestyle2">
			<tr>
				<td>
					<hr />
				</td>
			</tr>
			<tr>
				<td>${pageDown}</td>
			</tr>
		</table>
	</form>
		</div>
  </body>
  <script>

		// 查询
		function cmt(){
			document.frmM.action = "<%=contextPath%>/cllyjlList!getList.do?page=1&c=c";
			document.frmM.submit();
		}
   
   		// 新建修改进入详细页面
		function toDetail(id){
			
			parent.addTab("材料领用记录", "<%=contextPath%>/cllyjl!initCllyjlDetail.do?id="+id,id+1);
    
		}
	
		// 批准, 审核
		function toConfirm(flag)
		{
		
				var msg = flag == '1' ? '提交':'审核通过';
				if(flag=='0'){msg='驳回';}
				if(!isChecked("id")) {
		 			alert("请选择要" + msg + "选中的记录");
		 			return false;
		 		}
		    	if(confirm("确定要" + msg + "选中的记录吗？")) {
		        	document.frmM.action = "<%=contextPath%>/plan!confirmMonthPlan.do?flag=" + flag;
					document.frmM.submit();
		    	}
		}

		// 删除
		function deleteIt()
		{
			if(!isChecked("id")) {
		 		alert("请选择要删除的记录");
		 		return false;
		 	}
		    if(confirm("确定要删除选中的记录吗？")) {
		       	document.frmM.action = "<%=contextPath%>/cllyjl!deleteCllyjl.do?";
				document.frmM.submit();
		    }
		}
			
		// 点击checkbox 获得选中的id 给 hidden
		function getAllIds(obj) {
			
				var hiddenids = document.getElementById("hiddenids").value;
				
				var thisid = obj.value;
				var chkflag = obj.checked;
				
				if (chkflag) {
					if (hiddenids == "") {
						hiddenids = "," + thisid + ",";
					} else {
						hiddenids += thisid + ",";
					}
				} else {
					
					if (hiddenids.indexOf("," + thisid + ",") != -1) {
					
						hiddenids = hiddenids.replace(("," + thisid + ","), ",");
					}
				}
				
				if (hiddenids == ",") {
					hiddenids = "";
				}
				
				 document.getElementById("hiddenids").value = hiddenids;

		}
		
		
		
		// 打开详细任务
		function openDetail(recordid) {
		
			var str = "<table width='100%'  border='0'><tr><td width='10%'><b>材料类别</td><td width='10%'><b>材料名称</td><td width='10%'><b>领用数量</td><td width='35%'><b>材料型号</td><td width='10%'><b>仓库名称</td></tr>";
			$.ajax({
				type: "post",
				url : "<%=contextPath%>/cllyjl!getClkcmx.do",
				dataType:'json',
			    async : false,
				data: 'id=' + recordid,
				success: function(json,state){

					if (json != null && json.length > 0) {
						for (var i=0; i<json.length;i++) {
							str += '<tr><td width="10%">' + json[i]["cllb"] + '&nbsp;</td><td width="10%">' + json[i]["clmc"] + '&nbsp;</td><td width="10%">' + json[i]["lysl"]+json[i]["cldw"]+ '&nbsp;</td><td width="35%">' + json[i]["clxh"] + '&nbsp;</td><td width="10%">' + json[i]["ckmc"] + '&nbsp;</td></tr>'
						}
					}

				},
				error:function(json) {
					alert("异步失败！");
				}
			});
					
			str += '</table>';

			var flag = "0";
		    if(document.getElementById('nr' + recordid).innerHTML != "" && document.getElementById('tr' + recordid).style.display!="") {
		         document.getElementById('tr' + recordid).style.display="";
		      	$('#imgc' + recordid).show();
		      	$('#imgo' + recordid).hide();
		         return;
		    } 
		      
		    if (document.getElementById('nr' + recordid).innerHTML == ""){
		      	$('#nr' + recordid).html(str);
		      	document.getElementById('tr' + recordid).style.display="";
		      	$('#imgc' + recordid).show();
		      	$('#imgo' + recordid).hide();
		      	flag = "1";
		    }
		      
		    if (flag == "0") {
		      	document.getElementById('tr' + recordid).style.display="none";
		      	
		         $('#imgc' + recordid).hide();
		         $('#imgo' + recordid).show();
		     }

		}
		            
		
		
	</script>
</html>
